package com.starsray.dynamic.datasource.controller;

import com.starsray.dynamic.datasource.annotation.DefaultDs;
import com.starsray.dynamic.datasource.bean.R;
import com.starsray.dynamic.ds.core.Datasource;
import com.starsray.dynamic.ds.params.DatasourceProperties;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Set;

/**
 * ds控制器
 *
 * @author starsray
 * @date 2023/02/23
 */
@RestController
@RequestMapping("ds")
public class DsOperatorController {

    @Resource
    private Datasource datasource;

    @GetMapping("list")
    @DefaultDs
    public R<Set<String>> list() {
        return R.success(datasource.listDatasource());
    }

    @DefaultDs
    @PostMapping("addDatasource")
    public R<Set<String>> addDatasource(@RequestBody DatasourceProperties property) {
        return R.success(datasource.addDatasource(property));
    }

    @DefaultDs
    @DeleteMapping("remove")
    public R<Boolean> remove(@RequestParam("poolName") String poolName) {
        return R.success(datasource.removeDatasource(poolName));
    }
}
